<template>
  <div class="bgf_info">
    <div class="center" v-if="flag">
      <div class="dlex2-div">
        <img
          class="imaget"
          src="@/assets/image/icon_wechat.png"
          alt="404"
        /><span class="titleTxt4">微信支付</span>
      </div>
      <div class="cer_info">
        <span>交易将在{{OrderCloseDate}}后关闭，请及时付款！</span>
        <span style="font-size: 16px">收款方：华夏元道文化科技有限公司</span>
      </div>
      <div class="dlex2-div">
        <div class="images" v-if="imgFlag">
          <vue-qr :text="imageUrls" :size="200"></vue-qr>
          <span>实付金额<a>{{totalPrice}}</a>元</span>
          <span
            >请在15分钟内完成支付，无法支付时请<a style="color: #0d4fae"
             href=""  >点击刷新</a
            ></span
          >
        </div>
        <div class="imager">
          <img src="@/assets/image/icon_tip.png" alt="" />
        </div>
      </div>
    </div>
    <div class="center" v-else>
      <div class="cen_info">
        <img src="@/assets/image/complete.png" alt="" />
        <span class="titleTxt4">支付成功</span>
        <span class="titleTxt1"
          >将在<a>{{ second }}</a
          >秒自动返回课程页面</span
        >
        <a-button type="primary"> 立即前往</a-button>
      </div>
    </div>
    <div class="qrcodeimg"></div>
  </div>
</template>

<script>
import vueQr from "vue-qr";
export default {
  components: {
    vueQr,
  },
  data() {
    return {
      flag: true,
      imgFlag: false,
      second: 3,
      imageUrls: "",
      selId: this.$route.query.id,
      yelogo: null,
      timeout:null,
      jumber:null,
      totalPrice:null,
      // 订单关闭时间
      OrderCloseDate:null,
    };
  },
  created() {
    this.getCallback(this.selId);
    this.getPaymentcode(this.selId);
  },
  methods: {
    // 获取付款码
    getPaymentcode(e) {
      this.$ajax({
        url: "/order/wxpay/pay/code?orderId=" + e,
        method: "post",
        params: {},
      }).then((res) => {
        if (res.code == 200) {
          this.imageUrls = res.data;
          this.imgFlag = true;
          // console.log(this.imageUrls);
        } else {
          this.imageUrls = "";
        }
      });
    },
    // 获取支付回调
    getCallback(e) {
      this.$ajax({
        url: "/order/order/get",
        method: "post",
        params: {
          orderNo: e,
        },
      }).then((res) => {
        if (res.code == 200) {
          if (
            res.data.payStatus != null &&
            res.data.payDate != null &&
            res.data.payCode != null
          ) {
            this.flag = false;
            this.jumpSuperior();
          } else {
            this.totalPrice=res.data.totalPrice;
            this.OrderCloseDate=res.data.OrderCloseDate;
             this.timeout = setTimeout(() => {
              this.getCallback(this.selId);
            }, 3000);
          }
        } else {
        }
      });
    },
    //双跳转
    jumpSuperior() {
      let num = 3;
      let  _th=this;
       _th.jumber =setInterval(function () {
        _th.second = --num;
        // console.log(_th.second);
        if (num < 1) {
          _th.$router.go(-2)
        }
      }, 1000);
    },
  },
  destroyed: function () {
    console.log("我已经离开了！");
    clearTimeout(this.timeout);
    clearInterval(this.jumber);
  },
};
</script>



<style lang="less" scoped>
.bgf_info {
  background-color: #ffffff;
  padding-top: 40px;
  .center {
    width: 1200px;
    height: 728px;
    padding: 40px;
    margin: 0 auto;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.15);
    .imaget {
      width: 36px;
      margin-right: 16px;
    }
    .cer_info {
      margin-top: 7px;
      span {
        display: block;
        margin-top: 16px;
        font-size: 18px;
        font-family: PingFang SC;
        color: #333333;
      }
    }
    .images {
      width: 350px;
      margin-left: 278px;
      text-align: center;
      span {
        display: block;
        margin-top: 16px;
        font-size: 16px;
        font-family: PingFang SC;
        color: #333333;
      }
      img {
        width: 258px;
        height: 258px;
        margin: 0 auto;
        text-align: center;
      }
    }
    .imager {
      width: 252px;
      height: 402px;
      img {
        width: 100%;
      }
    }
    .cen_info {
      width: 300px;
      margin: 0 auto;
      text-align: center;
      img {
        width: 80px;
      }
      span {
        margin-top: 20px;
      }
      .titleTxt1 {
        display: block;
        margin-bottom: 20px;
      }
    }
  }
}
</style>